namespace DotNetNuke.UI.WebControls
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Web.UI;

    public class NodeImageCollection : CollectionBase, IStateManager
    {
        protected bool m_isTrackingViewState;

        public NodeImageCollection()
        {
        }

        public NodeImageCollection(NodeImageCollection value)
        {
            this.AddRange(value);
        }

        public NodeImageCollection(NodeImage[] value)
        {
            this.AddRange(value);
        }

        public int Add(NodeImage value)
        {
            int num2 = this.List.Add(value);
            if (this.m_isTrackingViewState)
            {
                value.TrackViewState();
                value.SetDirty();
            }
            return num2;
        }

        public int Add(string ImageUrl)
        {
            return this.Add(new NodeImage(ImageUrl));
        }

        public void AddRange(NodeImage[] value)
        {
            int num2 = value.Length - 1;
            for (int i = 0; i <= num2; i++)
            {
                this.Add(value[i]);
            }
        }

        public void AddRange(NodeImageCollection value)
        {
            int num2 = value.Count - 1;
            for (int i = 0; i <= num2; i++)
            {
                this.Add((NodeImage) value.List[i]);
            }
        }

        public bool Contains(NodeImage value)
        {
            return (this.GetImage(value.ImageUrl) != null);
        }

        public bool Contains(string strImageUrl)
        {
            return (this.GetImage(strImageUrl) != null);
        }

        public void CopyTo(NodeImage[] array, int index)
        {
            this.List.CopyTo(array, index);
        }

        private NodeImage GetImage(string strUrl)
        {
            foreach (NodeImage image2 in this.List)
            {
                if (StringType.StrCmp(strUrl, image2.ImageUrl, false) == 0)
                {
                    return image2;
                }
            }
            return null;
        }

        private int GetImageIndex(string strUrl)
        {
            int num3 = this.List.Count - 1;
            for (int i = 0; i <= num3; i++)
            {
                if (StringType.StrCmp(strUrl, ((NodeImage) this.List[i]).ImageUrl, false) == 0)
                {
                    return i;
                }
            }
            return -1;
        }

        public int IndexOf(NodeImage value)
        {
            return this.GetImageIndex(value.ImageUrl);
        }

        public int IndexOf(string strImageUrl)
        {
            return this.GetImageIndex(strImageUrl);
        }

        public void Insert(int index, NodeImage value)
        {
            this.List.Insert(index, value);
        }

        public void LoadViewState(object state)
        {
            if (state != null)
            {
                object[] objArray = (object[]) state;
                int num2 = objArray.Length - 1;
                for (int i = 0; i <= num2; i++)
                {
                    NodeImage image = new NodeImage();
                    this.Add(image);
                    ((IStateManager) image).TrackViewState();
                    ((IStateManager) image).LoadViewState(RuntimeHelpers.GetObjectValue(objArray[i]));
                }
            }
        }

        public void Remove(NodeImage value)
        {
            this.List.Remove(value);
        }

        public object SaveViewState()
        {
            if (this.Count == 0)
            {
                return null;
            }
            object[] objArray = new object[this.Count + 1];
            int num2 = this.Count - 1;
            for (int i = 0; i <= num2; i++)
            {
                objArray[i] = RuntimeHelpers.GetObjectValue(this[i].SaveViewState());
            }
            return objArray;
        }

        public NodeImage[] ToArray()
        {
            NodeImage[] imageArray=null;
            imageArray = (NodeImage[]) Utils.CopyArray((Array) imageArray, new NodeImage[(this.Count - 1) + 1]);
            this.CopyTo(imageArray, 0);
            return imageArray;
        }

        public void TrackViewState()
        {
            this.m_isTrackingViewState = true;
        }

        public bool IsTrackingViewState
        {
            get
            {
                return this.m_isTrackingViewState;
            }
        }

        public NodeImage this[int index]
        {
            get
            {
                return (NodeImage) this.List[index];
            }
            set
            {
                this.List[index] = value;
            }
        }

        //public bool System.Web.UI.IStateManager.IsTrackingViewState
        //{
        //    get
        //    {
        //        return this.m_isTrackingViewState;
        //    }
        //}
    }
}

